package android.activities;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

public class NewPasswordActivity extends Activity implements OnClickListener {
	/** Called when the activity is first created. */
	
	EditText t1, t2, t3, t4;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_password);
        View button6 = findViewById(R.id.button6);
        button6.setOnClickListener(this);
        View button7 = findViewById(R.id.button7);
        button7.setOnClickListener(this);
        View button8 = findViewById(R.id.button8);
        button8.setOnClickListener(this);
        t1 = (EditText)findViewById(R.id.editText2);
    	t2 = (EditText)findViewById(R.id.editText11);
    	t3 = (EditText)findViewById(R.id.editText3);
    	t4 = (EditText)findViewById(R.id.editText1);
    }
    
    public void onClick(View v) {
    	switch(v.getId()) {
    	case R.id.button6:
    		finish();
    		break;
    	case R.id.button7:
    		BaseActivity.base.addValue(t1.getText().toString(), t2.getText().toString(), t3.getText().toString(), t4.getText().toString());
        	finish();
        	break;
    	case R.id.button8:
    		Random generator = new Random();
    		int dlugosc = generator.nextInt(7) + 6;
    		StringBuilder sb = new StringBuilder();
    		int znak;
    		for (int i = 0; i < dlugosc; i++)
    		{
    			znak = generator.nextInt(93) + 33;
    			sb.append((char) znak);
    		}
    		t3.setText(sb);
    		break;
    	}
    }
}
